<?php
    $hanhdong=$_GET['hanhdong'];
    if($hanhdong=="taomoi1"){
        $hanhdong="taomoi";
        $tranggoidi="thannhan";
    }else{
        $tranggoidi="";
    }
    
    
    if ($hanhdong == "taomoi"){
        $action="../controller/xuly_themmoi_capnhat_thannhan.php";
        $tenform="Thêm mới thân nhân";
        $tenthannhan="";
        $gioitinh="";
        $ngaySinh="";
        $quanhe="";
        $ghichu="";
        $yeucau="themmoi";   
    }else{
        $action="../controller/xuly_themmoi_capnhat_thannhan.php";
        
        $ten1=$_GET['ten1'];
        $ten=$_GET['ten'];
        
        if(isset($ten1)){
            $tenthannhan=$ten1;
            $tranggoidi="thannhan";
        }elseif(isset($ten)){
            $tenthannhan=$ten;
            $tranggoidi="";            
        }
        
        $tenform="Cập Nhật Thông Tin";
        $sql_load_tn= "select*from thannhan where TenThanNhan = '$tenthannhan'";
        //echo $sql_load_tn;
        $kq_load_tn = executeQuery($sql_load_tn);
        
        while ($row = mysql_fetch_array($kq_load_tn)){
        $idnhanvien=$row['id_NhanVien'];
        $gioitinh=$row['GioiTinh'];
        $ngaysinh=$row['NgaySinh'];
        $quanhe=$row['QuanHe'];
        $ghichu=$row['GhiChu'];
        $yeucau="capnhat";
        }
    }
?>
    <div id="caidat">
        <div class="formHeader">
            <p> <?php echo $tenform ;?></p>
        
        </div>
        <div id="formContent">
            <form action="<?php echo $action; ?>" method="post" id="frmthannhan" name="frmthannhan" onsubmit="return kiemtrafrm();">
                <table cellspacing = 0 cellpadding =0>
                <tr>
                    <input type="hidden" name="tranggoidi" value="<?php echo $tranggoidi ; ?>" />
                    <td>Mã Nhân viên</td>
                    <?php

                        //include "../util/dataUtil.php";
                        $sql_load_manv = "select id_NhanVien from nhanvien";
                        $kq_manv = executeQuery($sql_load_manv);
                        
                        echo "<td>
                            <select name='manv'>";
                            
                        while ($mnv = mysql_fetch_array($kq_manv)) { 
                        $mnv_select=$mnv['id_NhanVien'];
                        echo "
                            <option value = '".$mnv_select."'"; 
                            
                            if ($mnv_select==$idnhanvien){echo "selected='true'";}
                            
                            echo ">".$mnv_select."</option>";
                            
                            }
                        
                        echo"</select></td>";
                        
                        
                        
                    ?>
                    </tr>
                    <tr>
                        <td align="right">Tên Thân Nhân</td>
                        
                        <td>
                            <input type="hidden" name="hanhdong" value="<?php echo $yeucau; ?>" />
                            <input type="hidden" name="tencu" value="<?php echo $tenthannhan; ?>"/>
                            <input type="hidden" name="macu" value="<?php echo $idnhanvien; ?>"/>
                            <input type="text" size="30" id="tentn" name="tentn" value="<?php echo $tenthannhan; ?>" />
                        </td>
                    
                    </tr>
                    
                    <tr>
                        <td align="right">Giới tính</td>
                        
                        <td>
                            <input type="text" size="30" id="sex" name="sex" value="<?php echo $gioitinh; ?>" />
                        </td>
                    
                    </tr>
                    
                    <tr>
                        <td align="right">Ngày Sinh</td>
                        
                        <td>
                            <input type="text" size="30" id="ngaysinh" name="ngaysinh" value="<?php echo $ngaysinh; ?>" />
                        </td>
                    
                    </tr>  
                    
                    <tr>
                        <td align="right">Quan hệ</td>
                        
                        <td>
                            <input type="text" size="30" id="quanhe" name="quanhe" value="<?php echo $quanhe; ?>" />
                        </td>
                    
                    </tr>                                        
                   
                        <td align="right">Ghi chú</td>
                        
                        <td>
                            <input type="text" size="30" id="ghichu" name="ghichu" value="<?php echo $ghichu; ?>" />
                        </td>
                    
                    </tr>
                    
                                        
                    <tr>
                        <td colspan="3" align ="center">
                            <input type="submit" value="Lưu Lại" id="themMoi" name="themMoi"/>
                            <input type="reset" value="Nhập Lại" id="nhapLai" name="nhapLai" onclick="clearTextbox();" />
                        </td>
 
                    </tr>
                    
                </table>
            </form>
        </div>
    </div>
    <div class="statusindex">
                <p> <?php echo $_SESSION['thongbao']; unset ($_SESSION['thongbao']);  ?></p>
    </div>
